package com.antdesignbackend.backend.common.http;

import java.util.HashMap;
import java.util.Map;

/**
 * demo 用法
 */
public class httpDemo {
    public static void main(String[] args) {

    }

    /**
     * 保持会话
     */
    private void keepCookie() {
        //封装登录参数
        Map<String, String> param = new HashMap<String, String>();
        param.put("action", "login");
        param.put("Username", "admin");
        param.put("Secret", "admin");
        //这就上面那个类
        HttpSession session = new HttpSession();
        try {
            //登录请求
            HttpClientResult httpClientResult = session.doGet("http://172.16.2.3/rawman", null, param);
            System.out.println(httpClientResult);
            //登陆后要操作的请求
            HttpClientResult httpClientResult2 = session.doGet("http://172.16.2.3/rawman?_=1543298733030&action=getExtStatus&Type=none", null, null);
            System.out.println(httpClientResult2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 不保持会话
     */
    private void noKeepCookie() {
        //封装登录参数
        Map<String, String> param = new HashMap<String, String>();
        param.put("action", "login");
        param.put("Username", "admin");
        param.put("Secret", "admin");
        try {
            //发送请求
            HttpClientResult httpClientResult = HttpClientUtils.doGet("http://172.16.2.3/rawman", param);
            System.out.println(httpClientResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
